<!doctype html>
<html>

  <head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="../css/mui.min.css" rel="stylesheet" />
    <style>
      ul {
        list-style: none;
        margin: 0;
        padding: 0;
      }
      .num{
      	font-size: 13px;
      	text-indent: 4px;
      }
      .flex {
        display: flex;
      }
      
      .user-each {
        padding: 5px 5px;
        position: relative;
      }
      .bgGray{
      	background-color: #F8F8F8;
      }
      .img-box {
        flex: 2;
      }
      
      .img-box img {
        height: 70px;
        width: 70px;
        vertical-align: middle;
        text-align: center;
      }
      
      .user-info-box {
        flex: 4;
        font-size: 13px;
        line-height: 24px;
      }
      
      .user-info-box div {
        margin-left: 5px;
      }
      
      .user-op-box {
        flex: 2;
        position: relative;
        height: 100%;
      }
      
      .user-op-box button {
        padding-left: 0;
        padding-right: 0;
      }
      .storage-choose-btn{
      	background-color: #FF9800;
      	border-color: #FF9800;
      	color: #fff;
      }
       .storage-choose-btn:active{
      	background-color: #ef9a60;
      }
      .recovery-num {
        position: absolute;
        right: 20px;
        font-size: 13px;
      }
      
      .choose-btn {
        width: 70%;
        position: absolute;
        bottom: -60px;
        right: 5px;
        text-align: center;
        font-size: 12px;
      }
      /*加载*/
      
      .mui-pull-bottom-pocket {
        visibility: visible;
      }
      
      .mui-pull-bottom-pocket .mui-pull-loading {
        visibility: visible;
      }
      /**/
      
      .no {
        text-align: center;
        font-size: 14px;
        line-height: 30px;
      }
    </style>
  </head>

  <body>
    <script src="../js/mui.min.js"></script>
    <div id="app">
      <div id="refreshContainer" class="mui-scroll-wrapper mui-content">
        <div class="mui-scroll">
          <ul class="userList">

          </ul>

          <script type="text/html" id="userList">
            <%if(list.length>0){%>
            <%for(var i=0;i<list.length;i++){%>
            	<%if(i%2===0){%>
            		  <li class="user-each">
            		<%}else {%>
            			<li class="user-each bgGray">
            			<%}%>
            	<div class="num">编号：<%=list[i].recyclingId%></div>
              <div class="flex">
                <div class="img-box">
                  <img src="<%=imgPath+list[i].header%>" alt="" />
                </div>
                <div class="user-info-box">
                  <div class="user-name">
                  	<%if(list[i].userNick){%>
                       <%=list[i].userNick%>
                    <%}else {%>
                    	--
                    <%}%>
                  </div>
                  <div class="user-id">
                    <%if(list[i].type ===1 ){%>
                    卡号：
                    <%}else {%>
                    ID：
                    <%}%>

                    <%=list[i].memberId%>
                  </div>
                  <div class="user-num">时间：
                    <%=list[i].recyclingDate%>
                  </div>
                </div>
                <div class="user-op-box">
                  <button type="button" data-index="<%=i%>" class="storage-choose-btn mui-btn choose-btn">清点入库</button>
                </div>
              </div>
            </li>
            <%}%>
            <%} else {%>
            <p class="no">暂无数据</p>
            <%}%>
          </script>
          <!--加载中-->
          <div class="mui-pull-bottom-pocket">
            <div class="mui-pull">
            </div>
          </div>
          <!--加载中-->
        </div>
      </div>
    </div>
    <script src="../config.js"></script>
    <script src="../js/template-native.js"></script>
    <script type="text/javascript">
      mui.init()
      var currentShopObj,
        params = {
          storeId: '',
          pageNo: 1,
          pageCount: 10
        },
        pageList = [],
        isLoading = false

      mui.plusReady(function() {
        receiveParams()
        getList()
        scroll()
        bindEvent()
      })
      //监听
      window.addEventListener('refresh', function(e) {
        getList()
      })

      function receiveParams() {
        var self = plus.webview.currentWebview()
        currentShopObj = self.currentShopObj
        params.storeId = currentShopObj.storeId
      }
      //获取数据
      function getList() {
        setLoading(1)
        isLoading = true
        config.ajax({
          url: '/recycling/checkRecycling',
          data: params,
          success: function(res) {
            console.log(JSON.stringify(res))
            if(res.result === 1) {
              pageTatol = res.data.pageTatol;
//判断 是卡用户  还是云用户 cardNo !==-1是卡用户
              res.data.recyclings.forEach(function(item,index){
                 if(item.cardNo !== -1 || item.cardName !=='' ){
                   item.userNick=item.cardName;
                   item.memberId=item.cardNo;
                   item.type=1;
                 }else{
                   item.type=2;
                 }
                item.memberId=item.memberId === -1 ? '- -' : item.memberId
              });
              console.log(JSON.stringify(res.data.recyclings))
              if(params.pageNo === 1) {
                pageList = res.data.recyclings
              } else {
                res.data.recyclings.forEach(function(item) {
                  pageList.push(item)
                })
              }
              setLoading(0)
              setPage()
              setTimeout(function() {
                isLoading = false
              }, 1000)
            } else {
              mui.toast(res.errormsg)
              setLoading(0)
            }
          }
        })
      }
      //
      function scroll() {
        mui('.mui-scroll-wrapper').scroll({
          scrollY: true,
          bounce: true,
          deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006，
        });
      }
      //滚动监听
      document.querySelector('.mui-scroll-wrapper').addEventListener('scrollend', function(e) {
        if(e.detail.y <= e.detail.maxScrollY) {
          if(isLoading === false) {
            if(++params.pageNo <= pageTatol) {
              getList()
            } else {
              setLoading(2)
            }
          }
        }
      });
      //设置加载状态
      function setLoading(type) {
        switch(type) {
          case 1:
            document.querySelector(".mui-pull").innerHTML = '<div class="mui-pull-loading mui-icon mui-spinner"></div>\
						<div class="mui-pull-caption">正在加载</div>'
            break
          case 2:
            document.querySelector(".mui-pull").innerHTML = '<div class="mui-pull-caption">没有更多</div>'
            break
          case 0:
            document.querySelector(".mui-pull").innerHTML = ''
            break
        }
      }
      //页面
      function setPage() {
        var html = template('userList', {
          list: pageList,
          imgPath: config.imgPath
        })
        mui('.userList')[0].innerHTML = html
      }

      function bindEvent() {
        mui(".userList").on('tap', '.storage-choose-btn', function(e) {
          var index = this.getAttribute('data-index')
          var title = '回收'
          mui.openWindow({
            url: './return-detail.html',
            id: 'return-detail',
            styles: {
              top: 0, //新页面顶部位置
              bottom: 0, //新页面底部位置         
              titleNView: {
                titleText: title,
                titleColor: "#FFFFFF",
                titleSize: "17px",
                backgroundColor: "#FF6800",
                autoBackButton: true,
                //                homeButton: true,
                buttons: [{
                  float: "right",
                  fontSize: "18px",
                  fontSrc: "_www/fonts/iconfont.ttf", //wap2app内置字体文件
                  text: "\ue602",
                  onclick: function() {
                    var allPage = plus.webview.all()
                    var nowPage = plus.webview.getWebviewById('index')
                    for(var i = 0; i < allPage.length; i++) {
                      if(allPage[i].getURL() !== nowPage.getURL()) {
                        plus.webview.close(allPage[i]);
                      }
                    }
                  }
                }],
                splitLine: {
                  color: "#CCCCCC",
                  height: "1px"
                }
              }
            },
            extras: {
              currentShopObj: currentShopObj,
              userRecovery: pageList[index]
            }
          })
        })
      }
    </script>
  </body>

</html>